package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricActivityInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricDetailResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricVariableInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricActivityInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricDetailQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricVariableInstanceQueryRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.HistoryApi")
public class HistoryApi {
    private ApiClient apiClient;

    public HistoryApi() {
        this(new ApiClient());
    }

    @Autowired
    public HistoryApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Get the binary data for a historic detail variable
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     * <p><b>200</b> - Indicates the historic detail instance was found and the requested variable data is returned.
     * <p><b>404</b> - Indicates the requested historic detail instance was not found or the historic detail instance does not have a variable with the given name or the variable does not have a binary stream available. Status message provides additional information.
     * @param detailId The detailId parameter
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getHistoricDetailVariableData(String detailId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'detailId' is set
        if (detailId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'detailId' when calling getHistoricDetailVariableData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("detailId", detailId);
        String path = UriComponentsBuilder.fromPath("/history/historic-detail/{detailId}/data").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the binary data for a historic task instance variable
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     * <p><b>200</b> - Indicates the variable instance was found and the requested variable data is returned.
     * <p><b>404</b> - Indicates the requested variable instance was not found or the variable instance does not have a variable with the given name or the variable does not have a binary stream available. Status message provides additional information.
     * @param varInstanceId The varInstanceId parameter
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getHistoricInstanceVariableData(String varInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'varInstanceId' is set
        if (varInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'varInstanceId' when calling getHistoricInstanceVariableData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("varInstanceId", varInstanceId);
        String path = UriComponentsBuilder.fromPath("/history/historic-variable-instances/{varInstanceId}/data").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the binary data for a historic task instance variable
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     * <p><b>200</b> - Indicates the task instance was found and the requested variable data is returned.
     * <p><b>404</b> - Indicates the requested task instance was not found or the process instance does not have a variable with the given name or the variable does not have a binary stream available. Status message provides additional information.
     * @param taskId The taskId parameter
     * @param variableName The variableName parameter
     * @param scope The scope parameter
     * @return List&lt;byte[]&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<byte[]> getHistoricTaskInstanceVariableData(String taskId, String variableName, String scope) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'taskId' is set
        if (taskId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'taskId' when calling getHistoricTaskInstanceVariableData");
        }

        // verify the required parameter 'variableName' is set
        if (variableName == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'variableName' when calling getHistoricTaskInstanceVariableData");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("taskId", taskId);
        uriVariables.put("variableName", variableName);
        String path = UriComponentsBuilder.fromPath("/history/historic-task-instances/{taskId}/variables/{variableName}/data").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "scope", scope));

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<byte[]>> returnType = new ParameterizedTypeReference<List<byte[]>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List historic activity instances
     *
     * <p><b>200</b> - Indicates that historic activity instances could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param activityId An id of the activity instance.
     * @param activityInstanceId An id of the historic activity instance.
     * @param activityName The name of the historic activity instance.
     * @param activityType The element type of the historic activity instance.
     * @param executionId The execution id of the historic activity instance.
     * @param finished Indication if the historic activity instance is finished.
     * @param taskAssignee The assignee of the historic activity instance.
     * @param processInstanceId The process instance id of the historic activity instance.
     * @param processDefinitionId The process definition id of the historic activity instance.
     * @param tenantId Only return instances with the given tenantId.
     * @param tenantIdLike Only return instances with a tenantId like the given value.
     * @param withoutTenantId If true, only returns instances without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @return DataResponseHistoricActivityInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricActivityInstanceResponse listHistoricActivityInstances(String activityId, String activityInstanceId, String activityName, String activityType, String executionId, Boolean finished, String taskAssignee, String processInstanceId, String processDefinitionId, String tenantId, String tenantIdLike, Boolean withoutTenantId) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/history/historic-activity-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityId", activityId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityInstanceId", activityInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityName", activityName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityType", activityType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "executionId", executionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "finished", finished));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "taskAssignee", taskAssignee));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processInstanceId", processInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processDefinitionId", processDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantIdLike", tenantIdLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get historic detail
     *
     * <p><b>200</b> - Indicates that historic detail could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param id The id of the historic detail.
     * @param processInstanceId The process instance id of the historic detail.
     * @param executionId The execution id of the historic detail.
     * @param activityInstanceId The activity instance id of the historic detail.
     * @param taskId The task id of the historic detail.
     * @param selectOnlyFormProperties Indication to only return form properties in the result.
     * @param selectOnlyVariableUpdates Indication to only return variable updates in the result.
     * @return DataResponseHistoricDetailResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricDetailResponse listHistoricDetails(String id, String processInstanceId, String executionId, String activityInstanceId, String taskId, Boolean selectOnlyFormProperties, Boolean selectOnlyVariableUpdates) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/history/historic-detail").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", id));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processInstanceId", processInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "executionId", executionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activityInstanceId", activityInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "taskId", taskId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "selectOnlyFormProperties", selectOnlyFormProperties));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "selectOnlyVariableUpdates", selectOnlyVariableUpdates));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricDetailResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricDetailResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of historic variable instances
     *
     * <p><b>200</b> - Indicates that historic variable instances could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param processInstanceId The process instance id of the historic variable instance.
     * @param taskId The task id of the historic variable instance.
     * @param excludeTaskVariables Indication to exclude the task variables from the result.
     * @param variableName The variable name of the historic variable instance.
     * @param variableNameLike The variable name using the like operator for the historic variable instance.
     * @return DataResponseHistoricVariableInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricVariableInstanceResponse listHistoricVariableInstances(String processInstanceId, String taskId, Boolean excludeTaskVariables, String variableName, String variableNameLike) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/history/historic-variable-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "processInstanceId", processInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "taskId", taskId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "excludeTaskVariables", excludeTaskVariables));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "variableName", variableName));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "variableNameLike", variableNameLike));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic activity instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic task instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the activities are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information
     * @param body The body parameter
     * @return DataResponseHistoricActivityInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricActivityInstanceResponse queryActivityInstances(HistoricActivityInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-activity-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricActivityInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic details
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long.
     * <p><b>200</b> - Indicates request was successful and the historic details are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricDetailResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricDetailResponse queryHistoricDetail(HistoricDetailQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-detail").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricDetailResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricDetailResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic variable instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the tasks are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricVariableInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricVariableInstanceResponse queryVariableInstances(HistoricVariableInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/query/historic-variable-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricVariableInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
